<?php
/**
* object-oriented file system manipulation as nodes.
* This file belongs to a webappkit package (kit)
* @link http://webappkit.net
* @package pathnodes
* @subpackage phplib
* @author J.Ducastel <nospam0@ducastel.name>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
/**
* registers as pathnode subclass
*/
pathnode::heritage('phplibfile',20);
/**
* php library file
*/
class phplibFile extends textFileNode {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
    /**
    *
    * @access
    * /
    function () {
        $this->__construct();
    }/**/
    
    /**
    * real constructor
    * @access
    * /
    function __construct() {
        
    }/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
    /**
    * 
    * @param
    * @access public
    * @return 
    */
    function selfDetector($path) {
        return is_file($path) and (ereg('.lib.php$',$path) or ereg('.class.php$',$path) or ereg('.function.php$',$path));
    }/**/
    
    /**
    * includes once library
    * @param
    * @access public
    * @return 
    */
    function import() {
        return include_once($this->relative_path);
    }/**/
    
    /**
    * return required classes
    * @param
    * @access public
    * @return array
    */
    function requiredClasses() {
        if (!$this->required_classes)
            $this->analyze();
        return $this->required_classes;
    }/**/
    
    /**
    * return classes defined into file
    * @param
    * @access public
    * @return 
    */
    function definedClasses() {
        if (!$this->classes)
            $this->analyze();
        return $this->classes;
    }/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
    /**
    * @var type desc
    */
    //var //
    var $classes=array();
    var $functions=array();
    var $required_classes=array();
    var $required_functions=array();
    var $lib_name;
/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/
    /**
    * parses file for class definitions, requirements etc
    * @param
    * @access private
    * @return bool
    */
    function analyze() {
        $content=$this->read();
        $tokens=token_get_all($content);
        $deb=wak::getservice('wakdebug');
        // echo $deb->vardump($tokens);
        for ($n=0; $n<count($tokens); $n++) {
            // searching for class definitions
            if ($tokens[$n][0]==T_CLASS) {
                $n+=2; $class=$tokens[$n][1];
                $this->classes[]=strtolower($class);
                continue;
            }
            // searching for heritage dependancies
            if ($tokens[$n][0]==T_EXTENDS) {
                $n+=2; $extends=$tokens[$n][1];
                $this->required_classes[]=strtolower($extends);
                continue;
            }
            // searching for instance use dependancies
            if ($tokens[$n][0]==T_NEW) {
                $n+=2;
                if ($tokens[$n][0]!=T_VAR) continue; // not a class name
                $class=$tokens[$n][1];
                if (!in_array($class,$this->classes))
                    $this->required_classes[]=strtolower($class);
                continue;
            }
        }
        // echo $deb->vardump($this);
        return true;
    }/**/
}
?>
